var Source;
var self = this;
require([
    'wangwu/sxyc/AppMap',
    'dojo/on',
    'dojo/query',
    'dojo/_base/lang'
], function(AppMap, on,djQuery){
    self.appmap = new AppMap('mapDiv', {

    });
    on(self.appmap,'map-did-load',function(){
        on(self.appmap.pumpStation,'layer-add',function(){
            Source = self.appmap.pumpStation.layer;
            self.appmap.anno.setDataSource(Source);
            self.appmap.anno.setMaxScale(200);
            self.appmap.anno.setMinScale(400000);
            self.appmap.anno.init();
            console.log("泵站加载完成")
        });
        self.appmap.pumpStation.setFieldRender('../images/bump.png');
        self.appmap.pumpStation.init();
        self.appmap.outletSump.setFieldRender('../images/outwater.png');
        self.appmap.outletSump.init();
        self.appmap.distributionStructure.setFieldRender('../images/switch.png');
        self.appmap.distributionStructure.init();
        on(self.appmap.bound,'layer-add',function(){
            Source = self.appmap.bound.layer;
            var extent = Source.graphics['0'].geometry.getExtent();
            //console.log(Source.graphics['0'].geometry._extent);
            //console.log(extent);
            //self.appmap.map.setExtent(extent);
        });
        self.appmap.bound.init();

        var btn1 = djQuery('#getStaion');
        on(btn1,"click",function(){
            console.log('点击按钮');
            var arr = [];
            for (var i = 0; i < Source.graphics.length; i++){
                var station = Source.graphics[i];
                var temp = "<tr class='tr-point' data-code='"+station.attributes.Id+"'>"+
                    "<td>"+station.attributes.NAME+"</td>"+
                    "<td>"+station.attributes.Id+"</td>"+
                    "</tr>";
                arr.push(temp);
            }
            var html = arr.join('');
            //console.log(html);
            $("#table tbody").append(html);
            var stcd;
            $('.tr-point').click(function(e){
                console.log(e);
                //map.setZoom(10);
                stcd = e.currentTarget.attributes["data-code"].value;//获取当前被点击的行的data-code属性的值
                self.appmap.locate.init(stcd,"泵站");
            });
        });
        var other = djQuery('#other');
        on(other,"click",function(){
            console.log('点击其他按钮');
            self.appmap.tiled01.hide();
            self.appmap.anno.setOption({tipfontColor:'rgba(0,0,0,2)'});

        });
        $("#exit").click(function(){
            location.href = '../home';
        });
    });
    self.appmap.init();

})